﻿/*
 * @author: wizardc
 */

using UnityEngine;
using UnityEngine.UI;

namespace Dou.UI
{
    /// <summary>
    /// 文本
    /// </summary>
    [ExecuteInEditMode]
    public class DText : Text
    {
        [SerializeField]
        private bool _useGray = false;

        /// <summary>
        /// 是否置灰
        /// </summary>
        public bool useGray
        {
            set
            {
                if (_useGray != value)
                {
                    _useGray = value;
                    SetGray(_useGray);
                }
            }
            get => _useGray;
        }

        protected override void Awake()
        {
            base.Awake();
            if (_useGray)
            {
                SetGray(true);
            }
        }

        public void SetColor(float r, float g, float b, float a = 1)
        {
            color = new Color(r, g, b, a);
        }

        public void SetColor32(int r, int g, int b, int a = 255)
        {
            color = new Color(r / 255.0f, g / 255.0f, b / 255.0f, a / 255.0f);
        }

        private void SetGray(bool isGray)
        {
            material = isGray ? UIAssetUtil.grayMat : null;
        }
    }
}
